import request from '../../../../../public/js/common/api/api.js';

const AuthUrl = Utils.CurDomain.AuthUrl;
const ShareUrl = Utils.CurDomain.ShareUrl;
const MasterDataUrl = Utils.CurDomain.MasterDataUrl;
const SysCfgUrl = Utils.CurDomain.SysCfgUrl;
const SysPlfUrl = Utils.CurDomain.SysPlfUrl;
const BaseCfgUrl = Utils.CurDomain.BaseCfgUrl

const _ajaxOptions = {
    contentType: 'application/json',
    dataType: 'text',
    async: true,
    dataFilter(data, type) {
        return data;
    }
};
export default class pigStockTakingApi {
    /**
     * 查询批次存栏数
     * @param data
     * @returns 
     */
    static getBreedbatchsNum(id, pigType) {
        return request.get(`${BaseCfgUrl}/breedbatchs/num/${id}/${pigType}`);
    }
    /**
    * 根据业务日期査询批次存栏信息
    * @param ids
    * @returns
    */
    static postBreedbatchsNum(data) {
        return request.post(`${BaseCfgUrl}/breedbatchs/pigtypenum`, data, true);
    }
    /**
     * 查询猪只盘点单Dt列表
     * @param data
     * @returns 
     */
    static postPigStockTakingList(data) {
        return request.post(`${ShareUrl}/pigstocktakings/list`, data);
    }

    /**
     * 创建 猪只盘点单
     * @param data
     * @returns 
     */
    static postpigStockTaking(data) {
        return request.post(`${ShareUrl}/pigstocktakings`, data, true, _ajaxOptions);
    }

    /**
     * 更新 猪只盘点单
     * @param data
     * @returns 
     */
    static putPigStockTaking(id, data) {
        return request.put(`${ShareUrl}/pigstocktakings/${id}`, data, true, _ajaxOptions);
    }

    /**
     * 查询 猪只盘点单详情
     * @param data
     * @returns
     */
    static getPigStockTaking(id) {
        return request.get(`${ShareUrl}/pigstocktakings/${id}`);
    }

    /**
     * 删除 猪只盘点单
     * @param data
     * @returns 
     */
    static deletePigStockTaking(id) {
        return request.delete(`${ShareUrl}/pigstocktakings/${id}`);
    }

    /**
     * 提交 猪只盘点单
     * @param ids
     * @returns 
     */
    static submitPigStockTaking(ids) {
        return request.put(`${ShareUrl}/pigstocktakings/submit`, ids);
    }
    /**
     * 反提交 猪只盘点单
     * @param ids
     * @returns 
     */
    static rollSubmitPigStockTaking(ids) {
        console.log(ids)
        return request.put(`${ShareUrl}/pigstocktakings/resubmit`, ids);
    }
    /**
     * 审核 猪只盘点单
     * @param ids
     * @returns 
     */
    static auditPigStockTaking(ids) {
        return request.put(`${ShareUrl}/pigstocktakings/audit`, ids);
    }
    /**
     * 反审核 猪只盘点单详情
     * @param ids
     * @returns 
     */
    static rollPigStockTaking(ids) {
        return request.put(`${ShareUrl}/pigstocktakings/reaudit`, ids);
    }

    /**
     * 盘点记录 单据操作
     * @param ids
     * @returns
     */
    static putBillStatusDispose(data, status, isRollback = false) {
        let _json = {
            1: [`/submit`, 2],
            2: [`/audit`, 3]
        }
        let _jsonRoll = {
            2: [`/resubmit`, 1],
            3: [`/reaudit`, 2]
        }
        let _url = isRollback ? _jsonRoll[status][0] : _json[status][0];
        return request.put(`${ShareUrl}/pigstocktakings${_url}`, { ids: data }, true, _ajaxOptions)
    }
    /**
     * 查询附件信息
     * @param ids
     * @returns 
     */
    static requestImagePath(id) {
        return request.get(`${SysCfgUrl}/yyattachments/${id}/url`);
    }

    /**
     * 获取人员信息
     * @param data
     * @returns 
     */
    static getPersonList() {
        return request.get(`${MasterDataUrl}/yypersons/by/q`);
    }

    /**
     * 获取用户拥有的组织信息
     * @param data
     * @returns 
     */
    static queryBaseOrgunitList() {
        return request.get(`${AuthUrl}/accounts/orgs`);
    }

    /**
     * 获取服务部信息
     * @param data
     * @returns 
     */
    static queryComDepList(upoid, aotype) {
        return request.get(`${SysPlfUrl}/yyorgunits/by/q?upoid=${upoid}&aotype=${aotype}`);
    }
}